package com.gxa.meiye.portal.service.zy.impl;

import com.gxa.meiye.core.utils.RestUtils;
import com.gxa.meiye.portal.service.zy.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-23  20:52
 */
@Service
public class PayServiceImpl implements PayService {
    @Autowired
    private RestTemplate restTemplate=null;
    @Override
    public String pay(String money) {
        return null;
    }

    @Override
    public String refund(String orderNumber) {
        String url="http://1.117.60.194:8080/order/refundsuccessful";
        MultiValueMap<String,Object> params=new LinkedMultiValueMap<>();
        params.add("orderNumber",orderNumber);
        Map map = RestUtils.postWithParams(url, params);
        Object data = map.get("data");
        return data.toString();
    }

    @Override
    public Integer refundUpdate(String orderNumber) {
        String url="http://1.117.60.194:8080/order/refundSuccessfulUpdate";
        MultiValueMap<String,Object> params=new LinkedMultiValueMap<>();
        params.add("orderNumber",orderNumber);
        Map map = RestUtils.postWithParams(url, params);
        Object data = map.get("data");
        Integer i=0;
        if (data.toString().equals("1")){
            i=1;
        }
        return i;
    }
}
